# konrad.smolinski@gmail.com
# date: 26/11/2010
# last update: 29/11/2010
#
#
# info:
#	This file generates a figure for simple binY-binX |Z=z 
#	figure can be used for demonstration of integration regions
# ------------------------------------------------------------------
# Call for libraries:
source("./rcLibSrc.R")

# original variables u=(u1,u2)
u2 <- seq(from=-10,to=10,len=100)
u1 <- NULL
for(i in 1:K) u1 <- cbind(u1,a0 + (a1+u2)*x[i])

# transformed variables v=(v1,v2)
v2 <- pnorm(u2,mean=mu.u1,sd=sqrt(b2+b1^2))
v1 <- NULL
for(i in 1:K) v1 <- cbind(v1,pnorm(u1[,i],mean=mu.u2,sd=1))

# Figure: 
pdf('../Graphs/tiramisu.pdf',width=10,height=6)
par(mfrow=c(1,2))
plot(c(-10,10),c(-10,10),ylab=expression(u[1]),xlab=expression(u[2]),col='white')
for(i in 1:K) points(u2,u1[,i],pch=19,cex=0.1,col=i,type='l')

abline(h=a0,col=3,lty=3)
abline(v=-a1,col=3,lty=3)

plot(c(0,1),c(0,1),ylab=expression(v[1]),xlab=expression(v[2]),col='white')
for(i in 1:K) points(v2,v1[,i],pch=19,cex=0.1,col=i,type='l')

abline(h=pnorm(a0,mean=mu.u2,sd=1),col=3,lty=3)
abline(v=pnorm(-a1,mean=mu.u1,sd=sqrt(b2+b1^2)),col=3,lty=3)

points(pts,pch=19,cex=0.25,col='grey')

for(i in 1:nOfCon) points(pts[conMat[,i],],pch=19,cex=0.25,col=i)
dev.off()